<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
<!--    医生姓名、号源医院、号源科室，日期-->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="4" :md="4" :sm="20">
            <a-form-item label="姓名">
              <a-input placeholder="医生姓名" v-model="queryParam.doctorName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="号源医院">
              <a-select v-model="queryParam.hospitalId" placeholder="请选择号源医院">
                <a-select-option v-for="optionHos in hospitalOption" :value="optionHos.id">{{optionHos.name}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="4" :md="4" :sm="20">
            <a-form-item label="号源科室">
              <a-select v-model="queryParam.departmentId" placeholder="请选择号源科室">
                <a-select-option v-for="optionDepart in departmentOption" :value="optionDepart.id">{{optionDepart.name}}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="5" :md="4" :sm="20">
            <a-form-item label="日期" :required="true" hasFeedback>
              <j-date placeholder="请选择日期" v-model="queryParam.visitTime" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleCreate()" type="primary" icon="plus">新增</a-button>-->
<!--      <a-button type="primary" icon="download" @click="handleExportXls('doctor_register')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->
<!--          <a-divider type="vertical" />-->
          <a-divider type="vertical" />
          <!-- invalid 1 删除 -->

          <!-- <a-popconfirm title="确定删除吗?" @confirm="() => handleStop(record,1)" v-if="record.invalid == 1">
            <a>删除</a>
          </a-popconfirm> -->
          <a-popconfirm title="确定停止挂号吗?" @confirm="() => handleStop(record,1)" v-if="record.invalid == 0">
            <a>停止挂号</a>
          </a-popconfirm>
          <a-popconfirm title="确定启用挂号吗?" @confirm="() => handleStop(record,0)" v-else-if="record.invalid == 1">
            <a>启用挂号</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <doctor-register-modal ref="modalForm" @ok="modalFormOk"></doctor-register-modal>
    <doctor-register-edit-modal ref="doctorRegisterEditModal"></doctor-register-edit-modal>
    <doctor-register-add-modal ref="doctorRegisterAddModal"></doctor-register-add-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DoctorRegisterModal from './DoctorRegisterModal'
  import DoctorRegisterEditModal from './modules/DoctorRegisterEditModal'
  import DoctorRegisterAddModal from './modules/DoctorRegisterAddModal'
  import { deleteAction, getAction,postAction } from '../../api/manage'
  import JDate from '@/components/jeecg/JDate'

  export default {
    name: 'DoctorRegisterList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      DoctorRegisterModal,
      DoctorRegisterEditModal,
      DoctorRegisterAddModal,
      JDate
    },
    inject:['reload'],
    data () {
      return {
        description: 'doctor_register管理页面',
        hospitalOption:{},
        departmentOption:{},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'医生ID',
            align:"center",
            dataIndex: 'doctorId'
          },
          {
            title:'医生',
            align:"center",
            dataIndex: 'doctorName'
          },
          {
            title:'号源医院',
            align:"center",
            dataIndex: 'hospitalName'
          },
          {
            title:'科室',
            align:"center",
            dataIndex: 'departmentName'
          },
          {
            title:'就诊号种',
            align:"center",
            dataIndex: 'type'
          },
          {
            title:'就诊日期',
            align:"center",
            dataIndex: 'visitTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'出诊时间段',
            align:"center",
            dataIndex: 'visitPart'
          },
         {
            title:'出诊开始时间',
            align:"center",
            dataIndex: 'startTime'
          },
         {
            title:'出诊结束时间',
            align:"center",
            dataIndex: 'endTime'
          },
          {
            title:'开始序号',
            align:"center",
            dataIndex: 'numStart'
          },
          {
            title:'结束序号',
            align:"center",
            dataIndex: 'numEnd'
          },
          {
            title:'余号',
            align:"center",
            dataIndex: 'surplusNum'
          },
          {
            title:'号源总数',
            align:"center",
            dataIndex: 'count'
          },
          {
            title:'额外费用',
            align:"center",
            dataIndex: 'price'
          },
         {
                title:'挂号费',
                align:"center",
                dataIndex: 'ghPrice'
              },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createUser'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>16?text.substr(0,16):text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/doctorRegister/doctorRegister/list",
          delete: "/doctorRegister/doctorRegister/delete",
          deleteBatch: "/doctorRegister/doctorRegister/deleteBatch",
          exportXlsUrl: "/doctorRegister/doctorRegister/exportXls",
          importExcelUrl: "/doctorRegister/doctorRegister/importExcel",
          signalUrl:"/doctorRegister/doctorRegister/signal",
          stopStatus:"/doctorRegister/doctorRegister/updateRegisterStatus",

        },
        dictOptions:{},
      }
    },
    created() {
      this.source();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //获取搜索时需要的资源
      source(){
        getAction(this.url.signalUrl).then((res)=>{
          this.hospitalOption = res.result.hospital
          this.departmentOption = res.result.department
        }).catch((error)=>{
          console.log(error);
        })
      },
      //编辑
      handleEdit(record){
        this.$refs.doctorRegisterEditModal.viewShow(record);
      },
      //新增挂号
      handleCreate(){
        this.$refs.doctorRegisterAddModal.viewShow();
        // this.modalMisible = true;
      },
      //删除
      handleDelete(record){
        var param = { id:record.id,invalid:1};
        getAction(this.url.stopStatus, param).then((res)=>{
          if(res.code === 200){
            this.$message.success(res.message)
            this.reload()
          }else{
            this.$message.warning(res.message)
          }
        }).catch((error)=>{
          console.log(error);
        })
      },
       //停止挂号
       handleStop(record,num){
        var param = { id:record.id,invalid:num};
        getAction(this.url.stopStatus, param).then((res)=>{
          if(res.code === 200){
            this.$message.success(res.message)
            this.reload()
          }else{
            this.$message.warning(res.message)
          }
        }).catch((error)=>{
          console.log(error);
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>